import { push } from "@/api/push"
import axios from "axios"
import { ElMessage } from "element-plus"

export const alertPush = (msg: any) => {
    if (msg.equipmentLocationCode && msg.equipmentLocationCode != 'ALL' && msg.alertGrade != 'INFO') {

        let data = {
            twinID: msg.equipmentLocationCode,
            severity: checkLv(msg.alertGrade),
            status: 1,
            sourceAlertKey: msg.equipmentType,
            summary: msg.alertContent,
            sourceIdentifier: msg.alertMessageId,
            lastOccurrence: msg.firstAlertTime
        }

        push([data]).then(res => {

        })
    }

}

export const alertListPush = (list: any) => {
    let alertList = []
    list.forEach(msg => {
        if (msg.equipmentLocationCode && msg.equipmentLocationCode != 'ALL' && msg.alertGrade != 'INFO') {

            let data = {
                twinID: msg.equipmentLocationCode,
                severity: checkLv(msg.alertGrade),
                status: 1,
                sourceAlertKey: msg.equipmentType,
                summary: msg.alertContent,
                sourceIdentifier: msg.alertMessageId,
                lastOccurrence: msg.firstAlertTime
            }
            alertList.push(data)

        }

    })
    push(alertList).then(res => {

    })
}

const checkLv = (lv: any) => {
    switch (lv) {
        case 'WARN':
            return 2
        case 'ERROR':
            return 1
    }
}
